package com.study.blog.common.result;

import lombok.Data;

/**
 * 最大的弊端就是我们后面每写一个接口都需要调用ResultData.success()这行代码对结果进行包装，重复劳动，浪费体力
 */
@Data
public class BaseResponse<T> {

    private int code = 500;

    private T data;

    private String msg;


    public static <T> BaseResponse<T> success(T object) {
        BaseResponse<T> response = new BaseResponse<T>();
        response.data = object;
        response.code = ReturnCode.REQUEST_SUCCESS.getCode();
        response.msg = ReturnCode.REQUEST_SUCCESS.getMessage();
        return response;
    }


    public static <T> BaseResponse<T> error(String message) {
        BaseResponse<T> response = new BaseResponse<T>();
        response.code = 400;
        response.msg = message;
        return response;
    }

    public static <T> BaseResponse<T> error(int code, String message) {
        BaseResponse<T> response = new BaseResponse<T>();
        response.code = code;
        response.msg = message;
        return response;
    }
}
